import 'package:flutter/material.dart';
import 'package:xindong/models/xindong_file_select_class.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/utils/xindong_text_util.dart';

class XinDongMediaAddPreview extends StatelessWidget {
  final XinDongSelectFileClass model;
  final Function()? onTap;
  final Function()? onTapDeletion;

  const XinDongMediaAddPreview({Key? key, required this.model, this.onTap, this.onTapDeletion}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Stack(
        fit: StackFit.expand,
        children: [
          Image.file(model.file, fit: BoxFit.cover),
          TextUtil.isEmpty(model.videoPath)
              ? const SizedBox()
              : Container(
                  alignment: Alignment.center,
                  child: ImageUtil.asset(AssetsRes.ICON_VIDEO_PLAY, width: 40, height: 40),
                ),
          Positioned(
            top: -5,
            right: -5,
            child: IconButton(
              icon: ImageUtil.asset(AssetsRes.ICON_CLOSE, width: 20, height: 24),
              alignment: Alignment.topRight,
              onPressed: onTapDeletion,
            ),
          ),
        ],
      ),
    );
  }
}
